package kr.ne.jay.SimpleString;

import java.util.Vector;

public class SimpleLinkConstraint implements IConstraint {
	public int index1;
	public int index2;
	public float restLen;
	
	public SimpleLinkConstraint(int idx1, int idx2, float len) {
		index1 = idx1;
		index2 = idx2;
		restLen = len;
	}
	
	@Override
	public void calcConstraint(Vector<VerletPoint> points) {
		Vector2f v1 = points.elementAt(index1).pos;
		Vector2f v2 = points.elementAt(index2).pos;
		Vector2f diff = v2.minus(v1);
		float diffLen = diff.len();
		float diffRatio = (diffLen-restLen)*0.5f/diffLen;
		v1.acc(diff.mul(diffRatio));
		v2.acc(diff.mul(-1.f));
	}
}
